package com.noble.meether.chat.unread.view;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;

public class BadgeView extends AppCompatTextView {

    public BadgeView(Context context) {
        this(context, null);
    }

    public BadgeView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BadgeView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    /**
     * set default params
     */
    private void init() {
        setVisibility(GONE);
    }

    /**
     * converts dip to px
     */
    private int dip2Px(float dip) {
        return (int) (dip * getContext().getResources().getDisplayMetrics().density + 0.5f);
    }

    /**
     * set the badge as a point
     */
    public void setPoint() {
        setTextColor(Color.TRANSPARENT);
        getLayoutParams().height = dip2Px(9);
        getLayoutParams().width = dip2Px(9);
        this.setLayoutParams(getLayoutParams());
    }
}